<template>
  <Card
    :tab-list="tabListTitle"
    v-bind="$attrs"
    :loading="isLoading"
    :active-tab-key="activeKey"
    @tabChange="onTabChange"
  >
    <p v-if="activeKey === 'tab1'">
      <VisitAnalysis :visit-item="analysisItem['visit_item']"
                     :active-item="analysisItem['active_item']"></VisitAnalysis>
    </p>
    <p v-if="activeKey === 'tab2'">
      <VisitAnalysisBar :month-item="analysisItem['month_item']"></VisitAnalysisBar>
    </p>
  </Card>
</template>

<script lang="ts">
  import {defineComponent, toRefs} from '@vue/runtime-core';
  import {reactive} from "vue";
  import {Card} from 'ant-design-vue';
  import VisitAnalysis from "./VisitAnalysis.vue";
  import VisitAnalysisBar from "./VisitAnalysisBar.vue";

  export default defineComponent({
    name: 'SiteAnalysis',
    components: {
      Card,
      VisitAnalysis,
      VisitAnalysisBar,
    },
    props: {
      isLoading: {
        type: Boolean,
        default: true,
      },
      analysisItem: {
        type: Object,
        default: null,
      },
    },
    setup() {

      const data = reactive({
        activeKey: 'tab1',
        tabListTitle: [{key: 'tab1', tab: '流量趋势',},
          {key: 'tab2', tab: '访问量',}],
      });

      const onTabChange = (key) => {
        data.activeKey = key;
      };

      return {
        ...toRefs(data),
        onTabChange,
      };
    }
  });

</script>

<style scoped>

</style>
